package com.java.test5;


/**
 * @author luzhikun
 * @date 2020/12/20-21:20
 * <p>
 * 手动抛出异常
 */
public class HandExceptionTest {
    public static void main(String[] args) {
        try {
            Student student = new Student();
            student.regist(-1000);
            System.out.println(student);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }


    }
}

class Student {
    private int age;

    public void regist(int age) throws Exception {
        this.age = age;
        if (age > 0) {
            System.out.println(age);
        } else {
//          System.out.println("您输入的数字有误");
//          throw new Exception("您输入的数字有误");
            throw new MyException("您输入的数字有误");
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age + '}';
    }
}


